import request from '@/utils/request';

// 商品列表
export const fetchGoodsList = (params: any) => {
  return request('/admin/goods', {
    method: 'GET',
    params,
  });
};

// 商品推荐
export const fetchGoodsRecommend = (id: number) => {
  return request(`/admin/goods/${id}/recommend`, {
    method: 'PATCH',
  });
};

// 商品推荐
export const fetchGoodsOn = (id: number) => {
  return request(`/admin/goods/${id}/on`, {
    method: 'PATCH',
  });
};

// 商品分类列表
export const fetchGoodsCategory = () => {
  return request('/admin/category', {
    method: 'GET',
  });
};

interface FetchGoodsAddProps {
  category_id: any;
  title: string;
  description: string;
  price: number;
  stock: number;
  cover: string;
  details: string;
}
// 添加商品
export const fetchGoodsAdd = (data: FetchGoodsAddProps) => {
  return request('/admin/goods', {
    method: 'POST',
    data,
  });
};

// 获取商品详情
export const fetchGoodsDetail = (id: number) => {
  return request(`/admin/goods/${id}`, {
    method: 'GET',
    params: { include: 'category' },
  });
};

// 更新商品
export const fetchUpdateGoods = (id: number, data: any) => {
  return request(`/admin/goods/${id}`, {
    method: 'PUT',
    data,
  });
};
